import java.util.ArrayList;
import java.util.Collections;
import java.util.stream.Stream;

public class day_01_stream_3 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list, "a", "b", "c", "ab", "abc", "c", "a", "c");

        // limit 获取前几个元素
        list.stream().limit(3).forEach(s -> System.out.print(s + ' '));
        System.out.println();

        // skip 跳过前几个
        list.stream().skip(3).forEach(s -> System.out.print(s + ' '));
        System.out.println();

        // distinct 元素去重 去重对象时需要重写hashCode和equals方法
        list.stream().distinct().forEach(s -> System.out.print(s + ' '));
        System.out.println();

        // concat 合并流
        ArrayList<String> list2 = new ArrayList<>();
        Collections.addAll(list2, "d", "e", "f");

        Stream.concat(list.stream(), list2.stream()).forEach(s -> System.out.print(s + " "));
        System.out.println();

        // map 转换流中的数据类型
        ArrayList<String> list3 = new ArrayList<>();
        Collections.addAll(list3, "龚汉强-21", "胡馨予-20", "王林林-22");
        // 获取列表年龄并打印
        list3.stream().map(s -> Integer.parseInt(s.split("-")[1])).forEach(s -> System.out.print(s + " "));
    }
}
